/**
 * @copyright 2022 indie Semiconductor
 *
 * This file is proprietary to indie Semiconductor.
 * All rights reserved. Reproduction or distribution, in whole
 * or in part, is forbidden except by express written permission
 * of indie Semiconductor.
 *
 * @file gpio_sfr.h
 */

#ifndef GPIO_SFR_H__
#define GPIO_SFR_H__

#include <stdint.h>

/* -------  Start of section using anonymous unions and disabling warnings  ------- */
#if   defined (__CC_ARM)
  #pragma push
  #pragma anon_unions
#elif defined (__ICCARM__)
  #pragma language=extended
#elif defined(__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050)
  #pragma clang diagnostic push
  #pragma clang diagnostic ignored "-Wc11-extensions"
  #pragma clang diagnostic ignored "-Wreserved-id-macro"
#elif defined (__GNUC__)
  /* anonymous unions are enabled by default */
#elif defined (__TMS470__)
  /* anonymous unions are enabled by default */
#elif defined (__TASKING__)
  #pragma warning 586
#elif defined (__CSMC__)
  /* anonymous unions are enabled by default */
#else
  #warning Not supported compiler type
#endif

typedef union {
  struct {
    uint8_t  GPAENA                   :  1;
    uint8_t  GPBENA                   :  1;
    uint8_t                           :  6; /*   (reserved) */
    uint32_t                           : 24; /*   (reserved) */
  };
  uint32_t WORD;
}GPIO_GPENA_t;

/*
    uint8_t  RE                   :  1; Pin x rising edge enable
    uint8_t  FE                   :  1; Pin x falling edge enable
*/
typedef union {
  struct {
    uint8_t  DIR                  :  1; /*!< Pin x output enable */
    uint8_t  IE                   :  1; /*!< Pin x interrupt enable */
    uint8_t  EDGE                 :  2; /* 00: disable, 01: rising, 10: falling, 11: both */
    uint8_t  CLR                  :  1; /*!< Pin x interrupt clear */
    uint8_t  ACTDET               :  1; /*!< Pin x activity interrupt */
    uint8_t                       :  2; /*   (reserved) */
  };
  uint8_t BYTE;
}GPIO_Cfg_t;

/**
 * @brief A structure to represent Special Function Registers for GPIO.
 */
typedef struct {

  uint8_t  GPADATA[1024];                     /*<! Port A data +0x000 */
  uint8_t  GPBDATA[1024];                     /*<! Port B data +0x400 */
  GPIO_GPENA_t  GPENA;  
  GPIO_Cfg_t    GPIO_CFG[12U];                /* only 0-8 valid */

} GPIO_SFRS_t;

/* --------  End of section using anonymous unions and disabling warnings  -------- */
#if   defined (__CC_ARM)
  #pragma pop
#elif defined (__ICCARM__)
  /* leave anonymous unions enabled */
#elif (__ARMCC_VERSION >= 6010050)
  #pragma clang diagnostic pop
#elif defined (__GNUC__)
  /* anonymous unions are enabled by default */
#elif defined (__TMS470__)
  /* anonymous unions are enabled by default */
#elif defined (__TASKING__)
  #pragma warning restore
#elif defined (__CSMC__)
  /* anonymous unions are enabled by default */
#else
  #warning Not supported compiler type
#endif

/**
 * @brief The starting address of GPIO SFRS.
 */
#define GPIO_SFRS ((__IO GPIO_SFRS_t *)0x50014000)

#endif /* end of __GPIO_SFR_H__ section */


